package com.dxy.app.widget.draw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * Description: 仿qq的泡泡
 * Auther: duxingyu
 * Time: 2017/8/4 17:22
 **/
public class ViscosityBallView extends View {
  
  public static final String TAG="TAG_ViscosityBallView";

  public ViscosityBallView(Context context) {
    super(context);
    init();
  }

  public ViscosityBallView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public ViscosityBallView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }


  private int width,height;
  private void init(){
    paint =new Paint();
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);

    move =new PointF();
  }

  @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    width =w;
    height =h;
  }

  private PointF move;
  private Paint paint;

  @Override protected void onDraw(Canvas canvas) {
    canvas.drawCircle(width/2,height/2,30,paint);
    canvas.drawCircle(move.x,move.y,100,paint);
  }


  @Override public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()){
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_MOVE:
        Log.i(TAG, "onTouchEvent: "+"move:("+event.getRawX()+","+event.getRawX()+")");
        move.x =event.getRawX();
        move.y =event.getRawY();


        invalidate();
        break;
      case MotionEvent.ACTION_UP:
        break;
    }
    return true;
  }
}
